package com.manfred.uddi.test;

import org.uddi4j.client.UDDIProxy;
import org.uddi4j.response.AuthToken;
import org.uddi4j.transport.TransportFactory;

import java.util.Vector;

import org.uddi4j.datatype.tmodel.TModel;
import org.uddi4j.response.TModelDetail;
import org.uddi4j.datatype.OverviewURL;
import org.uddi4j.datatype.OverviewDoc;
import org.uddi4j.util.CategoryBag;
import org.uddi4j.util.KeyedReference;

public class CreateNewInterface {

	public static void main(String args[]) {
		String inquiryURL = "http://localhost:8080/juddiv3/services/inquiryv2";
		String publishURL = "http://localhost:8080/juddiv3/services/publishv2";

		String userId = "juddi";
		String credential = "juddi";

		String transportClass = "org.uddi4j.transport.ApacheAxisTransport";
		System.setProperty(TransportFactory.PROPERTY_NAME, transportClass);

		UDDIProxy proxy = new UDDIProxy();

		try {

			proxy.setInquiryURL(inquiryURL);
			proxy.setPublishURL(publishURL);

			AuthToken token = proxy.get_authToken(userId, credential);
			System.out.println("Security authToken:"
					+ token.getAuthInfoString());

			Vector tModels = new Vector();
			TModel tModel = new TModel("",
					"http://www.daily-moon.com/classifieds-interface");

			tModel.setDefaultDescriptionString("Interface for the Daily Moon Classified "
					+ "Department web application");

			OverviewDoc overviewDoc = new OverviewDoc();
			overviewDoc.setDefaultDescriptionString("WSDL interface document");
			OverviewURL overviewURL = new OverviewURL(
					"http://www.nicholaschase.com/ClassifiedsService-interface.wsdl");
			overviewDoc.setOverviewURL(overviewURL);
			tModel.setOverviewDoc(overviewDoc);

			KeyedReference wsdlNotation = new KeyedReference(
					TModel.TYPES_TMODEL_KEY, "wsdlSpec",
					TModel.TYPES_TMODEL_KEY);
			KeyedReference typeNotation = new KeyedReference(
					"ntis-gov:naics:1997", "511110", TModel.NAICS_TMODEL_KEY);
			CategoryBag catBag = new CategoryBag();
			catBag.add(wsdlNotation);
			catBag.add(typeNotation);
			tModel.setCategoryBag(catBag);

			tModels.add(tModel);

			TModelDetail tModelDetail = proxy.save_tModel(
					token.getAuthInfoString(), tModels);

			Vector tModelVector = tModelDetail.getTModelVector();
			TModel tModelReturned = (TModel) (tModelVector.elementAt(0));
			System.out.println("TModel Saved: "
					+ tModelReturned.getNameString());
			System.out
					.println("TModel Key  : " + tModelReturned.getTModelKey());

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}